package cn.com.nes.site.entity.bo.ope;

import cn.com.nes.site.entity.bo.DeviceSaveBo;
import cn.com.nes.site.entity.em.CompanyTypeEnum;
import cn.com.nes.site.entity.vo.BaseVO;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 运营设备档案业务模型
 */
@Data
public class OpeEquipmentArchivesBo extends BaseVO {

    /**
     * 联系人
     */
    private String contact;

    /**
     * 联系电话
     */
    private String contactPhone;

    /**
     * 身份证号
     */
    private String idCardNumber;

    /**
     * 行政区划代码
     */
    private String areaCode;

    /**
     * 项目地址
     */
    private String projectAddress;

    /**
     * 经度
     */
    private BigDecimal longitude;

    /**
     * 纬度
     */
    private BigDecimal latitude;

    /**
     * 设备厂家ID
     */
    private String manufactureId;

    /**
     * 地点ID
     */
    private String ddId;

    /**
     * 公司类型
     */
    private String companyType;

    /**
     * 保存多设备使用
     */
    private List<DeviceSaveBo> deviceSaveBos;

    /**
     * 转换为安装保存信息
     * @return
     */
    public InstallInfoSaveBo toInstallInfoSaveBo() {
        InstallInfoSaveBo bo = new InstallInfoSaveBo();
        bo.setDdId(this.getDdId());
        bo.setManufactureId(this.getManufactureId());
        bo.setKhId("");    // todo 不确定客户编号怎么获取
        bo.setHtbh("");    // todo 不确定合同编号怎么获取
        bo.setXmdz(this.getProjectAddress());
        bo.setXmlxr(this.getContact());
        bo.setXmlxrdh(this.getContactPhone());
        bo.setSfzh(this.getIdCardNumber());
        bo.setXzqh(this.getAreaCode());
        bo.setXmmc(this.getProjectAddress());
        bo.setXmjc(this.getProjectAddress());
        bo.setXmbh(""); // todo 不确定项目编号怎么获取
        bo.setJd(this.getLongitude());
        bo.setWd(this.getLatitude());
        bo.setSjly(this.getOperatePlatform());
        bo.setScddh(""); // todo 不确定生产单号怎么获取
        return bo;
    }

    /**
     * 转换为设备保存数据
     * @return
     */
    public List<EquipmentInfoSaveBo> toEquipmentInfoSaveBo() {
        List<EquipmentInfoSaveBo> list = new ArrayList<>();
        for (DeviceSaveBo deviceSaveBo : this.deviceSaveBos) {
            EquipmentInfoSaveBo bo = new EquipmentInfoSaveBo();
            bo.setSbId(deviceSaveBo.getSbId());
            bo.setDdId(this.getDdId());
            bo.setManufactureId(deviceSaveBo.getManufacturerId());
            bo.setHtbh("");  // todo 不确定合同编号怎么获取
            bo.setSblxId(deviceSaveBo.getDeviceTypeId());
            bo.setSbxlh(deviceSaveBo.getDeviceSerialNo());
            bo.setJd(this.getLongitude());
            bo.setWd(this.getLatitude());
            bo.setSjly(this.getOperatePlatform());
            bo.setZbq(deviceSaveBo.getWarrantyDate());
            bo.setAgentId(CompanyTypeEnum._02.getKey()
                    .equals(this.getCompanyType()) ? this.getOperateUserCompanyId() : "");
            bo.setImages(deviceSaveBo.getImages());
            bo.setBz(deviceSaveBo.getRemark());
            bo.setCjsj(deviceSaveBo.getGmtCreate());
            bo.setCreateOper(deviceSaveBo.getCreateUserName());
            bo.setXgsj(deviceSaveBo.getGmtModified());
            bo.setUpOper(deviceSaveBo.getModifiedUserName());
            bo.setSfsc(deviceSaveBo.getDeleted());
            list.add(bo);
        }

        return list;
    }

}
